package com.mininglamp.hbga.util;

import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;

public class Log4j {

    private static final Logger log = LoggerFactory.getLogger(Log4j.class);

    public static final String LOG4J_CONFIG = "log4j.properties";
    public static final String LOG4J_CONFIG_FILE_NAME = "log4j.properties";

    public static void configure() {
        String log4jFile = System.getProperty(LOG4J_CONFIG);
        if (Strings.isNullOrEmpty(log4jFile)) {
            log4jFile = Files.join(ConfigHelper.APP_CONF_DIR, LOG4J_CONFIG_FILE_NAME);
        }
        log.info("Use log4j config file: {}", log4jFile);
        try {
            PropertyConfigurator.configure(log4jFile);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
